package com.libraryManage.controller;

import com.libraryManage.commons.utils.ResponseEntity;
import com.libraryManage.service.BookManageService;
import com.libraryManage.vo.BookManageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @CreateDate 2021-01-26
 * @Author yufang
 */
@Api(tags={"图书管理接口"})
@RestController
@CrossOrigin
@RequestMapping("manage/book")
public class BookController {

    @Autowired
    public BookManageService bookManageService;

    @ApiOperation("查询所有图书")
    @ApiResponses({
            @ApiResponse(code=0, message="成功"),
            @ApiResponse(code=500, message="系统异常"),
            @ApiResponse(code=999, message="未登录"),
            @ApiResponse(code=1000, message="数据有效性检查不通过"),
            @ApiResponse(code=1001, message="业务规则检查不通过")
    })
    @RequestMapping(value = "/list" , method = RequestMethod.POST)
    public ResponseEntity<List<BookManageVo>> getList(@RequestBody BookManageVo vo){
        return bookManageService.getList(vo);
    }

    @ApiOperation("图书上架or下架")
    @ApiResponses({
            @ApiResponse(code=0, message="成功"),
            @ApiResponse(code=500, message="系统异常"),
            @ApiResponse(code=999, message="未登录"),
            @ApiResponse(code=1000, message="数据有效性检查不通过"),
            @ApiResponse(code=1001, message="业务规则检查不通过")
    })
    @RequestMapping(value = "/updateBookState" , method = RequestMethod.GET)
    public ResponseEntity<List<BookManageVo>> updateBookState(int bookId,int bookState){
        return bookManageService.updateBookState(bookId,bookState);
    }

    @ApiOperation("更新图书基本信息")
    @ApiResponses({
            @ApiResponse(code=0, message="成功"),
            @ApiResponse(code=500, message="系统异常"),
            @ApiResponse(code=999, message="未登录"),
            @ApiResponse(code=1000, message="数据有效性检查不通过"),
            @ApiResponse(code=1001, message="业务规则检查不通过")
    })
    @RequestMapping(value = "/updateBookData" , method = RequestMethod.POST)
    public ResponseEntity<List<BookManageVo>> updateBookData(@RequestBody BookManageVo vo){
        return bookManageService.updateBookData(vo);
    }

    @ApiOperation("获取热门图书")
    @ApiResponses({
            @ApiResponse(code=0, message="成功"),
            @ApiResponse(code=500, message="系统异常"),
            @ApiResponse(code=999, message="未登录"),
            @ApiResponse(code=1000, message="数据有效性检查不通过"),
            @ApiResponse(code=1001, message="业务规则检查不通过")
    })
    @RequestMapping(value = "/hotBook" , method = RequestMethod.GET)
    public ResponseEntity<List<BookManageVo>> getHotBook(){

        return bookManageService.getHotBook();

    }

    @ApiOperation("更新热门书籍")
    @ApiResponses({
            @ApiResponse(code=0, message="成功"),
            @ApiResponse(code=500, message="系统异常"),
            @ApiResponse(code=999, message="未登录"),
            @ApiResponse(code=1000, message="数据有效性检查不通过"),
            @ApiResponse(code=1001, message="业务规则检查不通过")
    })
    @RequestMapping(value = "/updateBookHot" , method = RequestMethod.GET)
    public ResponseEntity<List<BookManageVo>> updateHotBook(int hotState,int bookId){

        return bookManageService.updateHotBook(hotState,bookId);

    }

}
